package com.ptswitch.material.util.security;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.ptswitch.material.model.security.Permission;

public class PermissionUtil {
    public static final List<Permission> permissions = new ArrayList<Permission>();
    //root
    public static final Permission All = new Permission("root", "系统所有权限", null);
    //material
    public static final Permission MaterialAll = new Permission("material", "物料-所有权限", All);
    public static final Permission MaterialCreate = new Permission("create", "物料-创建", MaterialAll);
    public static final Permission MaterialCreateLimit = new Permission("limit", "物料-创建-受限", MaterialCreate);
    public static final Permission MaterialCreatePower = new Permission("power", "物料-创建-不受限", MaterialCreate);
    public static final Permission MaterialEdit = new Permission("edit", "物料-修改", MaterialAll);
    public static final Permission MaterialEditLimit = new Permission("limit", "物料-修改-受限", MaterialEdit);
    public static final Permission MaterialEditPower = new Permission("power", "物料-修改-不受限", MaterialEdit);
    public static final Permission MaterialDelete = new Permission("delete", "物料-删除", MaterialAll);
    public static final Permission MaterialClear = new Permission("clear", "物料-清空", MaterialAll);
    public static final Permission MaterialImport = new Permission("import", "物料-导入", MaterialAll);
    public static final Permission MaterialExport = new Permission("export", "物料-导出", MaterialAll);
    public static final Permission MaterialList = new Permission("list", "物料-查看列表", MaterialAll);
    public static final Permission MaterialView = new Permission("view", "物料-查看", MaterialAll);
    //
    public static final Permission MaterialAttachmentAll = new Permission("attachment", "物料-附件-所有权限", MaterialAll);
    public static final Permission MaterialAttachmentUpload = new Permission("upload", "物料-附件-上传", MaterialAttachmentAll);
    public static final Permission MaterialAttachmentDelete = new Permission("delete", "物料-附件-删除", MaterialAttachmentAll);
    public static final Permission MaterialAttachmentDownload = new Permission("download", "物料-附件-下载", MaterialAttachmentAll);
    //
    public static final Permission BomAll = new Permission("bom", "单板表-所有权限", All);
    public static final Permission BomCreate = new Permission("create", "单板表-创建", BomAll);
    public static final Permission BomEdit = new Permission("edit", "单板表-修改", BomAll);
    public static final Permission BomDelete = new Permission("delete", "单板表-删除", BomAll);
    public static final Permission BomClear = new Permission("clear", "单板表-清空", BomAll);
    public static final Permission BomDownload = new Permission("download", "单板表-下载", BomAll);
    public static final Permission BomList = new Permission("list", "单板表-查看列表", BomAll);
    public static final Permission BomView = new Permission("view", "单板表-查看", BomAll);
    //contract
    public static final Permission ContractAll = new Permission("contract", "合同-所有权限", All);
    public static final Permission ContractList = new Permission("list", "合同-查看列表", ContractAll);
    public static final Permission ContractView = new Permission("view", "合同-查看", ContractAll);
    public static final Permission ContractCreate = new Permission("create", "合同-创建", ContractAll);
    public static final Permission ContractEdit = new Permission("edit", "合同-修改", ContractAll);
    public static final Permission ContractCancel = new Permission("cancel", "合同-取消", ContractAll);
    public static final Permission ContractAskOk = new Permission("askOk", "合同-申请完成", ContractAll);
    public static final Permission ContractAskDelete = new Permission("askDelete", "合同-申请删除", ContractAll);
    public static final Permission ContractDelete = new Permission("delete", "合同-删除", ContractAll);
    public static final Permission ContractAskReset = new Permission("askReset", "合同-申请激活", ContractAll);
    public static final Permission ContractReset = new Permission("reset", "合同-激活", ContractAll);
    public static final Permission ContractExport = new Permission("export", "合同-导出", ContractAll);
    public static final Permission ContractSearch = new Permission("search", "合同-搜索", ContractAll);
    public static final Permission ContractSendEmail = new Permission("sendEmail", "合同-发送邮件", ContractAll);
    //
    public static final Permission ContractItemView = new Permission("item.view", "合同-合同项-查看", ContractAll);
    public static final Permission ContractItemList = new Permission("item.list", "合同-合同项-查看列表", ContractAll);
    public static final Permission ContractItemAdd = new Permission("item.add", "合同-合同项-添加", ContractAll);
    public static final Permission ContractItemDelete = new Permission("item.delete", "合同-合同项-删除", ContractAll);
    public static final Permission ContractItemEdit = new Permission("item.edit", "合同-合同项-修改", ContractAll);
    public static final Permission ContractItemExamine = new Permission("item.examine", "合同-合同项-验货", ContractAll);
    public static final Permission ContractItemReceive = new Permission("item.receive", "合同-合同项-收货", ContractAll);
    public static final Permission ContractItemReturn = new Permission("item.return", "合同-合同项-退货", ContractAll);
    //
    public static final Permission ContractAttachment = new Permission("attachment", "合同-附件-所有权限", ContractAll);
    public static final Permission ContractAttachmentUpload = new Permission("upload", "合同-附件-上传", ContractAttachment);
    public static final Permission ContractAttachmentDelete = new Permission("delete", "合同-附件-删除", ContractAttachment);
    public static final Permission ContractAttachmentDownload = new Permission("download", "合同-附件-下载", ContractAttachment);
    //
    public static final Permission ContractInvoiceAsk = new Permission("finance.invoice.ask", "合同-申请发票", ContractAll);
    public static final Permission ContractInvoiceReply = new Permission("finance.invoice.reply", "合同-答复发票申请", ContractAll);
    public static final Permission ContractPaymentAsk = new Permission("finance.payment.ask", "合同-申请付款", ContractAll);
    public static final Permission ContractPaymentReply = new Permission("finance.payment.reply", "合同-答复付款申请", ContractAll);
    public static final Permission ContractRefundAsk = new Permission("finance.refund.ask", "合同-申请退款", ContractAll);
    public static final Permission ContractRefundReply = new Permission("finance.refund.reply", "合同-答复退款申请", ContractAll);
    //
    public static final Permission EmailAddressAll = new Permission("emailAddress", "邮件地址-所有权限", All);
    public static final Permission AllExport = new Permission("all.export", "导出物料，单板表和用户", All);
    public static final Permission AllImport = new Permission("all.import", "导入物料，单板表和用户", All);
    //
    public static final Permission HlogAll = new Permission("hlog", "系统日志-所有权限", All);
    public static final Permission HlogDelete = new Permission("delete", "系统日志-删除", HlogAll);
    public static final Permission HlogClear = new Permission("clear", "系统日志-清空", HlogAll);
    public static final Permission HlogList = new Permission("list", "系统日志-列表", HlogAll);
    //
    public static final Permission AcAll = new Permission("ac", "系统访问控制", All);
    public static final Permission UserAll = new Permission("user", "系统访问控制-账户-所有权限", AcAll);
    public static final Permission UserCreate = new Permission("create", "系统访问控制-账户-创建", UserAll);
    public static final Permission UserEdit = new Permission("edit", "系统访问控制-账户-修改", UserAll);
    public static final Permission UserChangePassword = new Permission("changePassword", "系统访问控制-账户-修改密码", UserAll);
    public static final Permission UserDelete = new Permission("delete", "系统访问控制-账户-删除", UserAll);
    public static final Permission UserList = new Permission("list", "系统访问控制-账户-查看列表", UserAll);
    public static final Permission UserView = new Permission("view", "系统访问控制-账户-查看", UserAll);
    //
    public static final Permission RoleAll = new Permission("role", "系统访问控制-角色-所有权限", AcAll);
    public static final Permission RoleCreate = new Permission("create", "系统访问控制-角色-创建", RoleAll);
    public static final Permission RoleEdit = new Permission("edit", "系统访问控制-角色-修改", RoleAll);
    public static final Permission RoleDelete = new Permission("delete", "系统访问控制-角色-删除", RoleAll);
    public static final Permission RoleList = new Permission("list", "系统访问控制-角色-查看列表", RoleAll);
    //
    public static final Permission PermissionEdit = new Permission("permission.edit", "系统访问控制-权限-修改", AcAll);

    public static final void init() {
        Field[] fields = PermissionUtil.class.getDeclaredFields();
        for (Field field : fields) {
            if (field.getType() == Permission.class) {
                try {
                    Object o = field.get(new PermissionUtil());
                    if (o instanceof Permission) {
                        permissions.add((Permission) o);
                    }
                } catch (IllegalArgumentException e) {
                } catch (IllegalAccessException e) {
                }
            }
        }
    }

    static {
        init();
    }
//    public static void main(String args[]) {
//        init();
//    }
}
